﻿
namespace HSS.Xaml.UI.Controls
{
	#region Using Directives
	using System.Windows;
	using System.Windows.Controls;
	using System.Windows.Media;
	#endregion

	#region StringExtensions
	/// <summary>
	/// String Extensions.
	/// </summary>
	public static class StringExtensions
	{
		/// <summary>
		/// Measures the estimated <see cref="Size"/> of the string, given the font size, family and weight.
		/// </summary>
		/// <param name="text">The string being measured</param>
		/// <param name="fontSize">The FontSize.</param>
		/// <param name="fontFamily">The FontFamily.</param>
		/// <param name="fontWeight">The FontWeight.</param>
		/// <returns>The estimated <see cref="Size"/>.</returns>
		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "System.Windows.Controls.TextBlock.set_Text(System.String)")]
		public static Size Measure(this string text, double fontSize, FontFamily fontFamily, FontWeight fontWeight)
		{
			var tb = new TextBlock();
			if (fontSize > 0)
				tb.FontSize = fontSize;

			if (fontFamily != null)
				tb.FontFamily = fontFamily;

			tb.FontWeight = fontWeight;
			tb.Text = text + " ";

			var tb2 = tb;
			return new Size(tb2.ActualWidth, tb2.ActualHeight);
		}
	}
	#endregion
}